package action.article;

import org.apache.struts2.ServletActionContext;

import service.ArticleClassService;
import service.ArticleService;
import service.UserService;
import bean.User;

import com.opensymphony.xwork2.ActionSupport;

public class ViewArticlesAction extends ActionSupport {
	private int classid;
	private User user;
	private UserService userService;
	private ArticleClassService articleClassService;
	private ArticleService articleService;
	
	@Override
	public String execute() throws Exception {
		user=userService.viewUserById(user.getId());
		ServletActionContext.getRequest().setAttribute("user", user);
		if(classid==0){
			ServletActionContext.getRequest().setAttribute("articleClasses", user.getArticleClasses());
			ServletActionContext.getRequest().setAttribute("articles", user.getArticles());
		}else{
			ServletActionContext.getRequest().setAttribute("articleClasses", articleClassService.getAllArticleClassesByUserid(user.getId()));
			ServletActionContext.getRequest().setAttribute("articles", articleService.getArticlesByClassid(classid));
		}
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public int getClassid() {
		return classid;
	}

	public void setClassid(int classid) {
		this.classid = classid;
	}

	public ArticleClassService getArticleClassService() {
		return articleClassService;
	}

	public void setArticleClassService(ArticleClassService articleClassService) {
		this.articleClassService = articleClassService;
	}

	public ArticleService getArticleService() {
		return articleService;
	}

	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}

	
}
